package com.cgbl.service.ui

import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import com.alibaba.android.arouter.facade.annotation.Route
import com.cgbl.service.BR
import com.cgbl.service.R
import com.cgbl.service.databinding.AppActivitySetJobBinding
import com.cgbl.service.pop.ProjectFilterPop
import com.cgbl.service.vm.SetJobViewModel
import com.lxj.xpopup.XPopup
import com.robot.base.base.activity.GLBaseActivity
import com.robot.base.configs.AppConstants
import com.robot.base.util.ToastUtils

@Route(path = AppConstants.Router.Project.A_SET_JOB)
class SetJobActivity : GLBaseActivity<AppActivitySetJobBinding, SetJobViewModel>() {

    override fun initContentView(savedInstanceState: Bundle?): Int = R.layout.app_activity_set_job

    override fun initVariableId(): Int = BR.viewModel

    override fun initComponents() {
        addSingleTitleBar("选择职称")
        binding.complete.setOnClickListener {
            val job = binding.etJob.text.toString()
            if (TextUtils.isEmpty(job)) {
                ToastUtils.showShort("请选择职称!")
                return@setOnClickListener
            }
            val intent = Intent()
            intent.putExtra(AppConstants.BundleKey.MEMBER_JOB, job)
            setResult(RESULT_OK, intent)
            finishActivity()
        }
        viewModel.fetchJobList()
    }

    override fun initViewObservable() {
        viewModel.uc.showTypeDialog.observe(this) {
            val filterPop = ProjectFilterPop(this, binding.etJob.text.toString(), viewModel.list)
            XPopup.Builder(this).atView(binding.etJob).asCustom(filterPop).show()
            filterPop.setConfirmClickListener {
                filterPop.dismiss()
                binding.etJob.text = it
            }
        }
    }
}